package com.zjhcsoft.shop.sys.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.zjhcsoft.shop.sys.buffer.TypeBuffer;
import com.zjhcsoft.util.CommonUtil;
import com.zjhcsoft.util.Config;

public class MyServletContextListener implements ServletContextListener {
	private static final Logger logger = Logger
			.getLogger(MyServletContextListener.class);

	
	public void contextDestroyed(ServletContextEvent arg0) {
		logger.debug("系统关闭"
				+ CommonUtil.getNowTimeString("yyyy/MM/dd HH:mm:ss"));

	}


	public void contextInitialized(ServletContextEvent arg0) {
		ServletContext servlet_context = arg0.getServletContext();
		WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servlet_context);
		String contextPath = servlet_context.getContextPath();
		servlet_context.setAttribute("contextPath",contextPath);
		String base = servlet_context.getContextPath();
		servlet_context.setAttribute("base",base);
		String staticServer=Config.getString("resource.path");
		servlet_context.setAttribute("staticServer",staticServer);
		String upload_path = Config.getString("upload.path");
		servlet_context.setAttribute("upload.path", upload_path);
		String upload_web_path = Config.getString("upload.web.path");
		servlet_context.setAttribute("uploadServer", upload_web_path);
		
		//TypeDao carTypeDao = (TypeDao)context.getBean("carTypeDaoImpl");
		//初始化载入内存
		TypeBuffer.init();
		logger.debug("系统启动"
				+ CommonUtil.getNowTimeString("yyyy/MM/dd HH:mm:ss"));
		
	}
}
